-
Notifications
You must be signed in to change notification settings - Fork 16.6k
fix: Fix TypeError in Slice.get() method when using filter_by() with BinaryExpression #34769
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
Fix TypeError in Slice.get() method introduced in PR #29573. The method was incorrectly using filter_by() with a BinaryExpression from id_or_uuid_filter(), which expects keyword arguments. Changed to use filter() which accepts BinaryExpressions. This fixes: - Chart thumbnail generation failures - 9 failing tests (8 event logger, 1 multi-tenant) - All calls to Slice.get() with ID or UUID strings Added comprehensive test coverage: - Unit tests for Slice.get() method with mock verification - Integration tests for both ID and UUID lookup scenarios - Tests to prevent regression of filter_by usage 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've completed my review and didn't find any issues.
Files scanned
| File Path | Reviewed |
|---|---|
| superset/models/slice.py | ✅ |
Explore our documentation to understand the languages and file types we support and the files we ignore.
Check out our docs on how you can make Korbit work best for you and your team.
Fixed integration tests that were incorrectly passing UUID objects instead of string representations to Slice.get() method: 1. test_slice_get_by_uuid: Changed chart.uuid to str(chart.uuid) 2. test_slice_get_nonexistent_uuid: Changed invalid UUID string "non-existent-uuid-123" to proper UUID format using uuid.uuid4() The id_or_uuid_filter function was correctly designed to accept string inputs (id_or_uuid: str), but our tests were passing wrong data types. This fixes the GitHub Actions CI failures. Addresses issues identified in PR #34769 CI logs. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Co-authored-by: Copilot <[email protected]>
Co-authored-by: Copilot <[email protected]>
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Pull Request Overview
This PR fixes a TypeError in the Slice.get() method that was preventing chart thumbnail generation and breaking API calls. The bug was caused by incorrectly using filter_by() with a BinaryExpression when filter() should have been used.
- Fixed the SQLAlchemy query method from filter_by() to filter() in Slice.get()
- Added comprehensive unit tests to verify the fix and prevent regression
- Added integration tests to ensure real database scenarios work correctly
Reviewed Changes
Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.
| File | Description |
|---|---|
| superset/models/slice.py | One-line fix changing filter_by() to filter() in Slice.get() method |
| tests/unit_tests/models/slice_test.py | New unit test file with 5 tests covering mock verification and helper function testing |
| tests/integration_tests/charts/api_tests.py | Added 4 integration tests for real database scenarios with ID/UUID lookups |
| for test_input in test_cases: | ||
| try: | ||
| result = Slice.get(test_input) | ||
| # Success - no TypeError occurred, result can be None or a Slice. # noqa: E501 |
Copilot
AI
Aug 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The comment formatting is inconsistent with the period placement before the noqa comment. Consider moving the period after the noqa comment or removing it entirely for better readability.
| # Success - no TypeError occurred, result can be None or a Slice. # noqa: E501 | |
| # Success - no TypeError occurred, result can be None or a Slice # noqa: E501. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The # no qa is not part of the comment instead it's so we don't get an error saying the length is too long.
| # Should return a BinaryExpression that can be used with filter() | ||
| assert result is not None | ||
| # The important thing is it doesn't crash and returns a filter expression. # noqa: E501 | ||
|
|
Copilot
AI
Aug 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The same comment is duplicated in both test methods. Consider extracting this into a shared docstring or making the comments more specific to each test case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why would we remove a line break here. That would leave 0 breaks between this and the next test.
| result = id_or_uuid_filter(test_uuid) | ||
| # Should return a BinaryExpression that can be used with filter() | ||
| assert result is not None | ||
| # The important thing is it doesn't crash and returns a filter expression. # noqa: E501 |
Copilot
AI
Aug 20, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
[nitpick] The same comment is duplicated in both test methods. Consider extracting this into a shared docstring or making the comments more specific to each test case.
| # The important thing is it doesn't crash and returns a filter expression. # noqa: E501 |
| rv = self.get_assert_metric(uri, "get") | ||
| assert rv.status_code == 404 | ||
|
|
||
| def test_slice_get_by_id(self): |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we merge these tests together and avoid duplication? both for the success and non existent ones
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Are you saying combine the id ones together and the uuid ones together? I normally prefer them separate in case if one use case fails and the other one passes, but can see that the uuid one might not actually be testing anything if we aren't in the if statement clause.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yes, I mean, looking at the tests you can assert both things just with 1 extra assertion that's why I suggested merging them, but the ultimate goal is to DRY them because those tests are 95% the same
| from superset.models.slice import id_or_uuid_filter, Slice | ||
|
|
||
|
|
||
| class TestSlice: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Same comment from above
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Antonio-RiveroMartnez good call. Parameterized it so I'd still know if one of the use cases failed but no duplicated code.
Address PR reviewer feedback by consolidating duplicate test cases into parameterized tests while maintaining test isolation and clarity. Changes: - Unit tests: 5 separate tests → 3 parameterized tests (8 test cases) - Integration tests: 4 separate tests → 2 parameterized tests (4 test cases) - Fixed UUID no-op issue: Use pytest.skip() if chart.uuid is None - Added uuid import to integration tests Benefits: - Reduced code duplication significantly - Each parameter still runs as separate test case - Clear failure identification with descriptive test names - Easier to add new test scenarios - Better maintainability Test coverage remains comprehensive: - Mock-based contract testing for filter() vs filter_by() - Integration testing with real database calls - Error handling for non-existent IDs/UUIDs - BinaryExpression testing for id_or_uuid_filter function Addresses feedback from Antonio-RiveroMartnez while preserving the test isolation benefits originally preferred. 🤖 Generated with [Claude Code](https://claude.ai/code) Co-Authored-By: Claude <[email protected]>
Antonio-RiveroMartnez
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
lgtm
…BinaryExpression (#34769) Co-authored-by: Claude <[email protected]> Co-authored-by: Copilot <[email protected]> (cherry picked from commit 9de1706)
SUMMARY
Problem
The Slice.get() method introduced in PR #29573 was causing a TypeError that broke chart thumbnail generation.
Root Cause Analysis
The Bug
In superset/models/slice.py line 366, the code incorrectly used filter_by() with a BinaryExpression:
Why It Failed
Pattern Comparison
The bug was introduced when copying the UUID support pattern from Dashboard.get(), but using the wrong filter method:
Solution
One-line fix: Change filter_by() to filter() in Slice.get()
Impact & Testing
What This Fixes
Comprehensive Test Coverage Added
Unit Tests (tests/unit_tests/models/slice_test.py - 5 tests):
Integration Tests (tests/integration_tests/charts/api_tests.py - 4 tests):
Investigation Depth
🤖 Generated with Claude Code
BEFORE/AFTER SCREENSHOTS OR ANIMATED GIF
TESTING INSTRUCTIONS
ADDITIONAL INFORMATION